import React, { Component } from 'react'
import Top from './Top'
import Conter from './Conter'
import Footer from './Footer'
import CTX from './store/index'

/* 

状态提升:将多组件需要共享的数据 提升到父组件中 由父组件管理
*/

export default class Vote2 extends Component {

  state = {
    title: '晚上会不会洗澡',
    sup: 100,
    opp: 1
  }

  changeProson = (type, n) => {
    if (type) {
      this.setState({ sup: this.state.sup + n })
    } else {
      this.setState({ opp: this.state.opp + n })
    }
  }

  render() {
    return (<CTX.Provider value={{
      ...this.state,
      changeProson:this.changeProson,
    }}>
      <div>
        <Top></Top>
        <Conter></Conter>
        <Footer></Footer>
      </div>
    </CTX.Provider>

    )
  }
}
